package com.wgchao.pharmacymg.application.controller;

import com.wgchao.pharmacymg.Infrastructure.back.ResultCommon;
import com.wgchao.pharmacymg.application.service.DrugStorageService;
import com.wgchao.pharmacymg.application.vo.DrugStorageSave;
import com.wgchao.pharmacymg.application.vo.DrugStorageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: DrugStorageController
 * @author: wgchao
 * @createTime: 2019/11/18 10:58 AM
 * @Description: 药库信息管理
 */
@RestController
@RequestMapping("/pharmacymg/sys/ds")
@Api(tags = "药库信息管理")
public class DrugStorageController {
    @Autowired
    private DrugStorageService drugStorageService;

    @PostMapping("/save")
    @ApiOperation(value = "新增药库")
    @ApiParam(name = "drugStorageSave", value = "药库信息", required = true)
    public ResultCommon<DrugStorageVO> save(DrugStorageSave drugStorageSave, BindingResult bindingResult) throws Exception{
        if(bindingResult.hasErrors()){
            String error = "";
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                error += (fieldError.getDefaultMessage()+",");
            }
            return ResultCommon.fail(error);
        }
        return drugStorageService.save(drugStorageSave);
    }
}
